<template>
	<view class="records-page">
		<view class="record-title">
			<text>视导内容</text>
		</view>
		<view>
			<u-collapse accordion>
				<u-collapse-item v-for="target in targetData" :title="target.name">
					<u-tag slot="value" class="u-page__item__title__slot-title"
						:text="getFinishNum(target.children || []) +'/' + (target.children.length || 0)"
						borderColor="#F1F1F1" plain size="mini"
						:type="getFinishNum(target.children || []) < (target.children.length || 0)? 'primary': 'success'"></u-tag>
					<view v-for="(item,index) in target.children" :key="index" class="record-list"
						@click="viewContent(item)">
						<text class="u-collapse-content">{{item.name}}</text>
						<u-tag :text="getImproveText(item.improveState)"
							:type="getImproveType(item.improveState)" shape="circle" borderColor="#F1F1F1"
							size="mini"></u-tag>
					</view>
				</u-collapse-item>
			</u-collapse>
		</view>
	</view>
</template>

<script>
	import {
		auditingCommentSchoolTarget
	} from "../../../api/supervise/work.js"
	import {
		deepClone,
		handleTree
	} from "../../../utils/common.js"
	export default {
		data() {
			return {
				newestCommentData: {},
				targetData: []
			}
		},
		methods: {
			viewContent(item) {
				if (item.finishState !== 1) {
					this.$u.toast("提交指标后不可进入未完成指标");
					return;
				}
				uni.setStorageSync("targetId",item.id)
				uni.setStorageSync("targetName",item.name)
				uni.setStorageSync("targetImproveState",item.improveState)
				this.$tab.navigateTo("/pages/work/workCheck/metric-result");
			},
			getFinishNum(data) {
				let num = 0;
				data.forEach(item => {
					if (item.finishState === 1) {
						num++;
					}
				});
				return num;
			},
			getImproveText(improveState){
				
				let result = "";
				
				if(improveState===0){
					result = "待审核"
				}else if(improveState===1){
					result = "已通过"
				}else if(improveState===2){
					result = "未通过"
				}else{
					result = "已通过"
				}
				
				return result;
			},
			getImproveType(improveState){
				
				let result = "error";
				
				if(improveState===0){
					result = "error"
				}else if(improveState===1){
					result = "success"
				}else if(improveState===2){
					result = "info"
				}else{
					result = "success"
				}
				
				return result;
			}
			/*getTargetsBySchoolIdAndActivityIDExcludeThirdLevel() {
				let activityId = this.newestCommentData.activityId;
				let schoolId = this.newestCommentData.schoolId;
				let createTime = this.newestCommentData.createTime;
				getTargetsBySchoolIdAndActivityIDExcludeThirdLevel(activityId, schoolId, createTime).then(
					res => {
						if (res.status == 0) {
							this.targetData = handleTree(res.targets, 1);
						}

					})
			}*/
		},
		onLoad(option) {
			
			let schoolName = uni.getStorageSync("schoolName");
			let schoolId = uni.getStorageSync("schoolId");
			let activityId = uni.getStorageSync("activityId");
			
			uni.setNavigationBarTitle({
				title: schoolName
			})
			
			this.newestCommentData={};
			this.newestCommentData.schoolName = schoolName;
			this.newestCommentData.schoolId = schoolId;
			this.newestCommentData.activityId = activityId;
			
			auditingCommentSchoolTarget(activityId,schoolId).then(res=>{
				console.log(res)
				this.targetData = handleTree(res.targets, 1);
			})
			
			/*	
			if (Object.keys(option).length > 0) {
				const data = JSON.parse(decodeURIComponent(option.newestCommentData));
				this.newestCommentData = data;
				uni.setNavigationBarTitle({
					title: data.schoolName
				})
				this.getTargetsBySchoolIdAndActivityIDExcludeThirdLevel();
			}
			*/
		
		}
	}
</script>

<style lang="scss" scoped>
	.records-page {
		width: 100vw;

		.record-title {
			text-align: center;
			height: 6vh;
			line-height: 6vh;
		}

		.record-list {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 5vh;
			// line-height: 6vh;
		}
	}
</style>